Subject: Re: Problems with "multiple defined" at linking stage
Date: 11 Mar 1996 15:18:37 GMT
Organization: LAN-ACES, Inc.
Message-ID: <4i1g8d$b7i@uuneo.neosoft.com>
References: <1996Mar6.144651.26841@ucl.ac.uk>
NNTP-Posting-Host: 198.65.178.8
X-Newsreader: WinVN 0.92.5
In article <1996Mar6.144651.26841@ucl.ac.uk>, richard@nmr.ion.bpmf.ac.uk (Mr Richard Maunder) says:
>
>I am trying to build a C++ patch over a C function library, but am encountering some problems at the linking stage, where the ld reports :
>
>collect2: ld returned 2 exit status
>ld: /usr/tmp/cca176282.o: __imerrbuf: multiply defined
>
>I presume this is caused by a multiple include in the code, but I cannot see a way round it. The compiler (g++) makes no complaints when creating the obj
>
>The files I have are :
>
> 1) unc_c++_patch .h - The header for the patch. This had the standard :
>
> #ifndef UNC_CPLUSPLUS_PATCH
> #define UNC_CPLUSPLUS_PATCH
>
> extern "C" {
> #include "image.h"
> }
>
> ......protyping for C++ methods.
>
> #endif
>
> in it. The file image.h is the header for the C function library.
>
> 2) unc_c++_patch.cc - The methods for the C++ patch. Has a #include unc_c++_patch.h at the top.
>
> 3) simple.cc - The actual program - again has unc_c++_patch.h at top.
>
>I presume I should be able to compile unc_c++_patch.cc and simple.cc seperately and then link them, but won't the compiler include "image.h" both times -
>
>I hope that I'm not being too stupid ! Any help gartefully recieved...Please CC tany replies o my e-mail address.
>
>Thanks
>
>
>Richard
I have seen a similar thing a time or two with MS VC/C++. The objects compile successfully separately, but will not
link (especially if the header has the structure of a class, or a variable in it).
The only reasoning I can see is that when they are compiled, the preprocessor does not see the
variable (UNC_CPLUSPLUS_PATCH) defined any where. But when linked, there are now two definitions
(albeit the same) for everything that is in the header file (and anything included & used through it)